
// MFCD3D11TestView.h : interface of the CMFCD3D11TestView class
//

#pragma once
#include "RenderWnd.h"
#include "MainFrm.h"
#include "Dlg3DObjectRendering.h"
#include "DlgBRDFRendering.h"
#include "engine.h"
#include "MFCD3D11TestDoc.h"
#include "BMPDlg.h"

enum DISPHEIGHTDIR
{
	Y_DIR = 0,
	X_DIR,
};

class CMFCD3D11TestView : public CView
{
protected: // create from serialization only
	CMFCD3D11TestView();
	DECLARE_DYNCREATE(CMFCD3D11TestView)

// Attributes
public:
	CMFCD3D11TestDoc* GetDocument() const;
	CMainFrame* m_pMainFrame;
	CRenderWnd m_D3DWnd;
	CDlg3DObjectRendering m_dlg3DObjectRendering;
	CDlgBRDFRendering m_dlgBRDFRendering;
	CBMPDlg  m_dlg2DNDFVisual;
	CHeightBMPDlg m_dlg2dHeightBMP;

	bool   m_bAvg1DNDF;
	long m_lPercentDisplay;
	DISPHEIGHTDIR m_iCurHeightBMPDir;

	//Ellipsoid NDF params
	double m_fAlphaX_AGGX;
	double m_fAlphaY_AGGX;
	double m_fScalingFactor_AGGX;
	double m_fAdjustScalingFactor;
	unsigned int m_iHMDataWidth;
	unsigned int m_iHMDataHeight;
	double m_fDataPSize_x;
	double m_fDataPSize_y;

protected:
	std::vector<double> m_arrNDFCumulation_LargeRegion;
// Operations
public:
	inline CRenderWnd* GetCurrentMainRender() {return &m_D3DWnd;}
	void SetbAvg1DNDF(bool bAvg);
	inline void SetXYZFileLoadStatus(bool bStatus) {m_D3DWnd.SetXYZFileLoadStatus(bStatus);}
	inline void SetXYZFileProcessStatus(bool bStatus) {m_D3DWnd.SetXYZFileProcessStatus(bStatus);}
	void SetNormalWndSize(int iSize);
	void SetNFGaussianSigma(float fSigma);

	double getAlphaX_AGGX() {return m_fAlphaX_AGGX;}
	void setAlphaX_AGGX(double alpha_x) {m_fAlphaX_AGGX=alpha_x;}
	double getAlphaY_AGGX() {return m_fAlphaY_AGGX;}
	void setAlphaY_AGGX(double alpha_y) {m_fAlphaY_AGGX=alpha_y;}
	double getScalingFactor_AGGX() {return m_fScalingFactor_AGGX;}
	void setScalingFactor_AGGX(double fScale) {m_fScalingFactor_AGGX=fScale;}
	double getAdjustScalingFactor() {return m_fAdjustScalingFactor;}
	void setAdjustScalingFactor(double fScale) {m_fAdjustScalingFactor=fScale;}
	unsigned int getHMDataWidth() {return m_iHMDataWidth;}
	void setHMDataWidth(unsigned int iWidth) {m_iHMDataWidth=iWidth;}
	unsigned int getHMDataHeight() {return m_iHMDataHeight;}
	void setHMDataHeight(unsigned int iHeight) {m_iHMDataHeight=iHeight;}
	double getDataPSizeX() {return m_fDataPSize_x;}
	void setDataPSizeX(double fDataPSizeX) {m_fDataPSize_x=fDataPSizeX;}
	double getDataPSizeY() {return m_fDataPSize_y;}
	void setDataPSizeY(double fDataPSizeY) {m_fDataPSize_y=fDataPSizeY;}


protected:
	bool Plot1DSliceHeight(CMatlabEng* matlabEng, std::vector<CPoint>& arrPts, float fCur1DLength,  int iYDim, int iXDim);
	void Prepare1DSliceHeightData(CGrowableArray<double>& arrPtPos, CGrowableArray<double>& arrHeightVals,std::vector<CPoint>& arrPts, float fCur1DLength,  int iYDim, int iXDim);
	bool Plot1DNDFFunc_X(CMatlabEng* matlabEng,CXYZFileIO* pXYZFile);
	bool Plot1DNDFFunc_Y(CMatlabEng* matlabEng,CXYZFileIO* pXYZFile);
	bool Plot1DNDFFunc(CMatlabEng* matlabEng,CXYZFileIO* pXYZFile);
	void Prepare1DProfilDataSlice_X(CGrowableArray<double>& arrAngles, CGrowableArray<double>& arrNDFVals, CXYZFileIO* pXYZFile);
	void Prepare1DProfilDataSlice_Y(CGrowableArray<double>& arrAngles, CGrowableArray<double>& arrNDFVals, CXYZFileIO* pXYZFile);
	void Prepare2DFitGGXSlice_X(CGrowableArray<double>& arrAngles, CGrowableArray<double>& arrNDFVals, float a_x, float a_y, float b);
	void Prepare2DFitGGXSlice_Y(CGrowableArray<double>& arrAngles, CGrowableArray<double>& arrNDFVals, float a_x, float a_y, float b);
	void Prepare2DFitBeckmannSlice_X(CGrowableArray<double>& arrAngles, CGrowableArray<double>& arrNDFVals, float a_x, float a_y, float b);
	void Prepare2DFitBeckmannSlice_Y(CGrowableArray<double>& arrAngles, CGrowableArray<double>& arrNDFVals, float a_x, float a_y, float b);
	void ComputeNDFCumulationArray_Largeregion(CXYZFileIO* pSmallXYZFile);
	void queryXYZNormEstParamsFromUI(NORMALESTIMATEMETHOD& iCurEstMethod, int& iKernelSize, float& fGaussianSigma);
	
// Overrides
public:
	virtual void OnDraw(CDC* pDC);  // overridden to draw this view
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
	virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
	virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
	virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);

// Implementation
public:
	virtual ~CMFCD3D11TestView();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
	afx_msg void OnFilePrintPreview();
	afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
	afx_msg LRESULT OnRender(WPARAM,LPARAM);
	afx_msg LRESULT OnLoadXYZProcessing(WPARAM wParam, LPARAM lparam);
	afx_msg LRESULT OnLoadXYZStarted(WPARAM,LPARAM);
	afx_msg LRESULT OnLoadXYZFinished(WPARAM,LPARAM);
	afx_msg LRESULT OnProcessXYZStarted(WPARAM,LPARAM);
	afx_msg LRESULT OnProcessXYZFinished(WPARAM,LPARAM);
	afx_msg LRESULT OnProcessMXYZStarted(WPARAM,LPARAM);
	afx_msg LRESULT OnProcessMXYZFinished(WPARAM,LPARAM);
	afx_msg LRESULT OnNormEstUpdateStarted(WPARAM,LPARAM);
	afx_msg LRESULT OnNormEstUpdateFinished(WPARAM,LPARAM);
	afx_msg LRESULT OnRTHMStatStarted(WPARAM,LPARAM);
	afx_msg LRESULT OnRTHMStatFinished(WPARAM,LPARAM);
	afx_msg LRESULT OnRTVGonioStarted(WPARAM,LPARAM);
	afx_msg LRESULT OnRTVGonioFinished(WPARAM,LPARAM);
	afx_msg LRESULT OnRTVGonioMFilesStarted(WPARAM,LPARAM);
	afx_msg LRESULT OnRTVGonioMFilesFinished(WPARAM,LPARAM);
	afx_msg LRESULT OnComputeWBRDFSingleXYZStarted(WPARAM,LPARAM);
	afx_msg LRESULT OnComputeWBRDFSingleXYZFinished(WPARAM,LPARAM);
	afx_msg LRESULT OnComputeWBRDFMultipleXYZStarted(WPARAM,LPARAM);
	afx_msg LRESULT OnComputeWBRDFMultipleXYZFinished(WPARAM,LPARAM);

	DECLARE_MESSAGE_MAP()
public:
	//virtual void OnInitialUpdate();
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnSetFocus(CWnd* pOldWnd);
	virtual void OnInitialUpdate();
	virtual void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView);
	afx_msg void OnEditRender3dobject();
	afx_msg void OnEditRenderbrdf();
	afx_msg void OnDestroy();
	afx_msg void OnPlot1dndf();
	afx_msg void OnPlot1dndffuncY();
	afx_msg void OnPlot1dndffuncX();
	afx_msg void OnEditShow2dndfplot();
	afx_msg void OnEditSplitcoldir();
	afx_msg void OnEditComputendfmultiplefiles();
	afx_msg void OnEditSubstractfrombigndf();
	afx_msg void OnEditSplitrowdir();
	afx_msg void OnEditComputendfmultiplefilesrowdir();
	afx_msg void OnEditPlot1dndffuncYLargeregion();
	afx_msg void OnEditPlot1dndffuncXLargeregion();
	afx_msg void OnEditComputendfmultiplefiles8by8();
	afx_msg void OnEditSplitinaarbitrarysize();
	afx_msg void OnEditSaveasobjfile();
	afx_msg void OnEditComputendfmultiplefilesgeneral();
	afx_msg void OnEditShow2dheightmapbmp();	
	afx_msg void OnEditPlot1dsliceheightY();
	afx_msg void OnEditPlot1dsliceheightX();
	afx_msg void OnRaytracingstatisticaltest();
	afx_msg void OnEditRaytracingvirtualgoniotest();
	afx_msg void OnEditRaytracingvirtualgoniotestMfiles();
	afx_msg void OnEditShow2dndfplotLargeregion();
	afx_msg void OnEditDebugndfellipsoid();
	afx_msg void OnEditDebugsincoswave();
	afx_msg void OnEditGeneratexyzfilefromafm1dslices();
	afx_msg void OnEditComputewaveopticsbrdf();
	afx_msg void OnEditComputewaveopticsbrdfMfiles();
	afx_msg void OnEditPlotwaveopticbrdfcomp();
	afx_msg void OnEditLoadprecomputedwaveopticbrdf();
	afx_msg void OnEditGenerateplanarxyzfile();
	afx_msg void OnEditRaytracing1dsliceseg();
};

#ifndef _DEBUG  // debug version in MFCD3D11TestView.cpp
inline CMFCD3D11TestDoc* CMFCD3D11TestView::GetDocument() const
   { return reinterpret_cast<CMFCD3D11TestDoc*>(m_pDocument); }
#endif

